package com.mz.ozy.mvp.presenter;


import android.app.Activity;
import android.content.Context;

import com.mz.ozy.base.BasePresenterImpl;
import com.mz.ozy.bean.TransferBean;
import com.mz.ozy.bean.TransferUserBean;
import com.mz.ozy.mvp.model.TransferModel;
import com.mz.ozy.mvp.view.TransferContract;
import com.mz.ozy.net.MyObserver;
import com.mz.ozy.utils.RxUtil;

import org.json.JSONObject;

import okhttp3.ResponseBody;

/**
 * Created by administrator on 2018/12/3.
 */
public class TransferPresenter extends BasePresenterImpl<TransferContract.View> implements TransferContract.Presenter {

    private TransferModel mModel;

    public TransferPresenter() {
        mModel = new TransferModel();
    }


    @Override
    public void getTransferInfo(Activity activity, String type) {
        mView.dismissLoading();
        mModel.getTransferInfo(activity, type)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<TransferBean>(mView) {
                    @Override
                    public void onSuccesss(TransferBean bean) {
                        mView.getTransferInfoSuccess(bean);
                    }
                });
    }

    @Override
    public void obtainTransfer(Context context, String payType, String receivingAccount, String amt, String pwd) {
        mModel.obtainTransfer(context, payType, receivingAccount, amt, pwd)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject json) {
                        mView.obtainTransferSuccess(json);
                    }
                });
    }

    public void getUserName(Context context, String invitationCode) {
        mModel.getUserName(context, invitationCode)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<TransferUserBean>(mView) {
                    @Override
                    public void onSuccesss(TransferUserBean bean) {
                        mView.getUserNameSuccess(bean);
                    }
                });
    }
}
